package com.zhai.boot.async.log;

import com.zhai.boot.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @author Created by 翟凤玺
 * @package com.zhai.boot.async
 * @project-name zhai-boot
 * @description 业务日志 异步存储（mongo），tips：不能放到controller层使用
 * @create-datetime 2019-9-19 16:06
 */
@Slf4j
@Service
public class BizLogAsync {

    private static final String BUSINESS_NAME = "【异步 业务日志】";
    private static final String METHOD_SAVE = "（保存）";

    @Autowired
    private MongoTemplate mongo;

    @Async
    public void save(BizLogInfo log) {
        log.setDate(DateUtil.fmtLocalDateTimeToStr(DateUtil.getCurrentLocalDateTime(), DateUtil.DATETIME_FMT_3));
        mongo.insert(log, log.getTable());
    }

    @Async
    public void save(BizLogInOut log) {
        log.setDate(DateUtil.fmtLocalDateTimeToStr(DateUtil.getCurrentLocalDateTime(), DateUtil.DATETIME_FMT_3));
        mongo.insert(log, log.getTable());
    }
}